package com.cssl.gulimall.order.web;

import com.cssl.common.constant.order.PaymentConstant;
import com.cssl.common.vo.order.PayVO;
import com.cssl.gulimall.order.config.AliPayConfig;
import com.cssl.gulimall.order.service.impl.OrderServiceImpl;
import com.cssl.gulimall.order.service.impl.PayContextStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PayWebController {
    @Autowired
    OrderServiceImpl orderService;
    @Autowired
    PayContextStrategy payContextStrategy;
    @Autowired
    AliPayConfig aliPayConfig;

    /**
     * 创建支付
     * 返回text/html页面
     * @param orderSn       订单号
     */
    @ResponseBody
    @GetMapping(value = "/payOrder")
    public String htmlPayOrder(@RequestParam(value = "orderSn", required = false) String orderSn) throws Exception {
        PayVO payVo = orderService.getOrderPay(orderSn);
        String pay = aliPayConfig.pay(payVo);
        return pay;
    }
}
